package com.xhl.consul.tool.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Optional;

/**
 * @Author CazCen
 * @Date 2021/11/29 13:52
 */
@Api(tags = "Session 测试")
@RestController
@RequestMapping("/test/session")
@Slf4j
public class SessionController {


    @PostMapping("/do1")
    @ApiOperation("session do1")
    public void do1(HttpSession session, HttpServletRequest request, HttpServletResponse response){

        HttpSession session1 = request.getSession();

        log.info("session1:{}",session1);

        String requestedSessionId = request.getRequestedSessionId();

        log.info("requestedSessionId:{}",requestedSessionId);
        log.info("requestedSessionId getId:{}",session.getId());



        String s = request.changeSessionId();

        log.info("s:{}",s);

        String requestedSessionId2 = request.getRequestedSessionId();

        log.info("requestedSessionId2:{}",requestedSessionId2);

//        eOgAGUrEt_13MpDNCvNEE9snW3Y-ec_4T4kwOXH5


            session.setAttribute("aSessionKey","aSessionValue");
        session.setAttribute("bSessionKey","bSessionValue");
        session.setAttribute("cSessionKey","cSessionValue");



    }


    @PostMapping("/do2")
    @ApiOperation("session do2")
    public void do2(HttpSession session, HttpServletRequest request, HttpServletResponse response){

        // 关闭浏览器之后消失

        HttpSession session1 = request.getSession();

        Object aSessionKey = session1.getAttribute("aSessionKey");
        Object cSessionKey = session1.getAttribute("cSessionKey");
        Object bSessionKey = session1.getAttribute("bSessionKey");


    }

}
